<?php
/**
 * @var yii\web\View $this
 * @var backend\models\Meetings[] $meetings
 * @var $pages
 */
$this->title = '会议回收站';
\common\Utils\ViewUtils::addAssetBundle($this, \backend\assets\DataTable::className());
?>
<div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">会议回收</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
                <div id="example2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                    <div class="row">
                        <div class="col-sm-6"></div>
                        <div class="col-sm-6"></div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <table id="example2" class="table table-bordered table-hover dataTable" role="grid"
                                   aria-describedby="example2_info">
                                <thead>
                                <tr role="row">
                                    <th>会议主题</th>
                                    <th>开始时间</th>
                                    <th>结束时间</th>
                                    <th>会议地点</th>
                                    <th>创建时间</th>
                                    <th>管理操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                <?php foreach ($meetings as $key => $meeting): ?>
                                    <tr role="row" id="m_<?= $meeting->getId() ?>" class="meetings">
                                        <td><?= \common\Utils\Mbstring::substrWithApostrophe($meeting->title, 0, 10) ?></td>
                                        <td><?= $meeting->getStartAt(true) ?></td>
                                        <td><?= $meeting->getEndAt(true) ?></td>
                                        <td><?= $meeting->getLocationName() ?></td>
                                        <td><?= $meeting->getCreatedAt(true) ?></td>
                                        <td>
                                            <?= \yii\helpers\Html::a('恢复', ["rec", "id" => $meeting->getId()],['class'=>"rec"]) ?>
                                            <?= \yii\helpers\Html::a('彻底删除', ["del", "id" => $meeting->getId()], ['class' => "clean"]) ?>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>

                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-9">
                        </div>
                        <div class="col-sm-3">
                            <?= \yii\widgets\LinkPager::widget(['pagination' => $pages]); ?>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.box-body -->
        </div>
    </div>
</div>
<style>
    .meetings {
        cursor: pointer;
    }
</style>
<?php $this->beginBlock('jquery_script'); ?>
<script>
    $(document).ready(function () {
        $(".rec").click(function () {
            if (confirm("确定恢复该会议吗？")) {
                $.post($(this).attr('href'), {}, function (data) {
                    if (data == 1) {
                        window.location.reload();
                    } else {
                        alert("恢复失败");
                    }
                });
            }
            return false;
        });
        $(".del").click(function () {
            if (confirm("确定彻底删除该会议吗？会议的相关信息将同时被删除！")) {
                $.post($(this).attr('href'), {}, function (data) {
                    if (data == 1) {
                        window.location.reload();
                    } else {
                        alert("删除失败");
                    }
                });
            }
            return false;
        });
    });
</script>
<?php $this->endBlock(); ?>
